#ifndef USART_H
#define USART_H

#include "gd32f30x.h"


#define USART0_TX_SIZE	256
#define USART0_RX_SIZE	256

#define USART1_TX_SIZE	256
#define USART1_RX_SIZE	256

#define USART2_TX_SIZE	256
#define USART2_RX_SIZE	256

#define UART3_TX_SIZE	256
#define UART3_RX_SIZE	256

#define UART4_TX_SIZE	256
#define UART4_RX_SIZE	256

#define COMn                             5U

#define EVAL_COM0                        USART0
#define EVAL_COM0_CLK                    RCU_USART0
#define EVAL_COM0_TX_PIN                 GPIO_PIN_9
#define EVAL_COM0_RX_PIN                 GPIO_PIN_10
#define EVAL_COM0_GPIO_PORT              GPIOA
#define EVAL_COM0_GPIO_CLK               RCU_GPIOA
#define EVAL_COM0_IRQ                    USART0_IRQn

#define EVAL_COM1                        USART1
#define EVAL_COM1_CLK                    RCU_USART1
#define EVAL_COM1_TX_PIN                 GPIO_PIN_5
#define EVAL_COM1_RX_PIN                 GPIO_PIN_6
#define EVAL_COM1_GPIO_PORT              GPIOD
#define EVAL_COM1_GPIO_CLK               RCU_GPIOD
#define EVAL_COM1_IRQ                    USART1_IRQn

#define EVAL_COM2                        USART2
#define EVAL_COM2_CLK                    RCU_USART2
#define EVAL_COM2_TX_PIN                 GPIO_PIN_10//GPIO_PIN_8
#define EVAL_COM2_RX_PIN                 GPIO_PIN_11//GPIO_PIN_9
#define EVAL_COM2_GPIO_PORT              GPIOB//GPIOD
#define EVAL_COM2_GPIO_CLK               RCU_GPIOB//RCU_GPIOD
#define EVAL_COM2_IRQ                    USART2_IRQn

#define EVAL_COM3                        UART3
#define EVAL_COM3_CLK                    RCU_UART3
#define EVAL_COM3_TX_PIN                 GPIO_PIN_10
#define EVAL_COM3_RX_PIN                 GPIO_PIN_11
#define EVAL_COM3_GPIO_PORT              GPIOC
#define EVAL_COM3_GPIO_CLK               RCU_GPIOC
#define EVAL_COM3_IRQ                    UART3_IRQn

#define EVAL_COM4                        UART4
#define EVAL_COM4_CLK                    RCU_UART4
#define EVAL_COM4_TX_PIN                 GPIO_PIN_12
#define EVAL_COM4_RX_PIN                 GPIO_PIN_2
#define EVAL_COM4TX_GPIO_PORT            GPIOC
#define EVAL_COM4TX_GPIO_CLK             RCU_GPIOC
#define EVAL_COM4RX_GPIO_PORT            GPIOD
#define EVAL_COM4RX_GPIO_CLK             RCU_GPIOD
#define EVAL_COM4_IRQ                    UART4_IRQn

#define SP485_PIN						GPIO_PIN_12
#define SP485_GPIO_PORT					GPIOB
#define SP485_GPIO_CLK					RCU_GPIOB
#define SP485_TXEN						GPIO_BOP(SP485_GPIO_PORT) = SP485_PIN//gpio_bit_write(SP485_GPIO_PORT,SP485_PIN,SET)
#define SP485_RXEN						GPIO_BC(SP485_GPIO_PORT) = SP485_PIN//gpio_bit_write(SP485_GPIO_PORT,SP485_PIN,RESET)
#define SP485_Init                      gpio_init(SP485_GPIO_PORT, GPIO_MODE_OUT_PP, GPIO_OSPEED_50MHZ, SP485_PIN);

typedef struct
{
    unsigned char buffer[USART0_RX_SIZE];
    unsigned char nbRxCounter;
}UART_TC_RxVariate_T;
typedef struct
{
    unsigned char buffer[USART1_RX_SIZE];
    unsigned char nbRxCounter;
}UART_ESP_RxVariate_T;
typedef struct
{
    unsigned char buffer[USART2_RX_SIZE];
    unsigned char nbRxCounter;
}UART_LCD_RxVariate_T;

typedef struct
{
    unsigned char buffer[UART3_RX_SIZE];
    unsigned char nbRxCounter;
}UART_ADP_RxVariate_T;

typedef struct
{
    unsigned char buffer[UART4_RX_SIZE];
    unsigned char nbRxCounter;
}UART_VOI_RxVariate_T;





void USART_Init(void);
void D485_Send_Byte(uint8_t *data,int leng);
void ESP_Send_Byte(uint8_t *data,int leng);
void LCD_Send_Byte(uint8_t *data,int leng);
void ADP_Send_Byte(uint8_t *data,uint16_t leng);
void VOICE_Send_Byte(uint8_t *data,int leng);




#endif
